CMAKE_MINIMUM_REQUIRED(VERSION 3.5)

SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -O2 -std=c11")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}  -g -Wall -O2 -std=c++11")
# suppornt C++14, when gcc version > 5.1, use -std=c++14 instead of c++1y
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}  -g -Wall -O2 -std=c++1y")

set(CMAKE_CXX_STANDARD 11 CACHE STRING "The C++ standard to use")
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

#add_definitions(-std=c++11)


set(CMAKE_C_FLAGS ""  CACHE STRING "Flags used by the compiler during all build types.")
set(CMAKE_CXX_FLAGS ""  CACHE STRING "Flags used by the compiler during all build types.")

set(CMAKE_C_FLAGS_DEBUG ""  CACHE STRING "Flags used by the compiler during debug builds.")
set(CMAKE_CXX_FLAGS_DEBUG ""  CACHE STRING "Flags used by the compiler during debug builds.")

set(CMAKE_C_FLAGS_RELEASE ""  CACHE STRING "Flags used by the compiler during release builds.")
set(CMAKE_CXX_FLAGS_RELEASE ""  CACHE STRING "Flags used by the compiler during release builds.")

set(CMAKE_C_FLAGS "-fcompare-debug-second")
set(CMAKE_CXX_FLAGS "-fcompare-debug-second")

set(CMAKE_C_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_DEBUG "-g")               #### -D_GLIBCXX_USE_CXX11_ABI=01

set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")

set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O2 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O2 -DNDEBUG")

set( CMAKE_BUILD_TYPE "Debug" )

MESSAGE(STATUS "CMake version: " ${CMAKE_VERSION})
MESSAGE(STATUS "CMake system name: " ${CMAKE_SYSTEM_NAME})

project( pngTrans )
set(USER_PROJECT_NAME pngTrans)

set(virtualDisp
  virtualDisplay/soft_dev.c
)

set(Application
    Application/main.c
    Application/rgb2color.c
)

set(LibQuickLZ
    quicklz/quicklz.c
)
add_library(QuicklzStatic STATIC ${LibQuickLZ})
add_library(QuicklzShared SHARED ${LibQuickLZ})

set(Libpng
  png/adler32.c
  png/crc32.c
  png/infback.c
  png/inffast.c
  png/inflate.c
  png/inftrees.c
  png/zutil.c
  png/PNGdec.c
  bmp/save_bmp.c
)
add_library(pngStatic STATIC ${Libpng})
add_library(pngShared SHARED ${Libpng})

# set include file path
include_directories(
  quicklz/
  png/
  virtualDisplay/
  Application/
  bmp/
)


MESSAGE(STATUS "SRC: " ${Application} ${Libpng} ${LibQuickLZ} ${virtualDisp})

set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
link_directories(${PROJECT_SOURCE_DIR}/lib)

## debug cmd
# add_executable(quicklz quicklz/quicklz_sample.c)
add_executable(quicklz quicklz/decompress_buffer.c)
target_link_libraries(quicklz -lpthread -lrt -lm -ldl -std=c++11 QuicklzStatic)

add_executable(main_bmp bmp/main_bmp.c)
target_link_libraries(main_bmp -lpthread -lrt -lm -ldl -std=c++11)

add_executable(${USER_PROJECT_NAME} ${Application} ${virtualDisp})
target_link_libraries(${USER_PROJECT_NAME} -lpthread -lrt -lm -ldl -std=c++11  QuicklzStatic pngStatic)
